import config from '../../utils/config';
import {$wuxLoading} from '../../dist/index';

var util = require('../../utils/util');
var wxApi = require('../../utils/wxApi');
var wxRequest = require('../../utils/wxRequest');

var app = getApp();

var that;
Page({
  data: {
    movies:[ {url:'https://free.modao.cc/uploads3/images/1863/18633040/raw_1523024234.png'} ,
    {url:'https://free.modao.cc/uploads3/images/1863/18633040/raw_1523024234.png'} ,
    {url:'https://free.modao.cc/uploads3/images/1863/18633040/raw_1523024234.png'} ,
    {url:'https://free.modao.cc/uploads3/images/1863/18633040/raw_1523024234.png'}
    ]
  },
onLoad: function (options) {
	that=this;
	util.loading = $wuxLoading();
	
	if (!util.judge.isNull(options.oldunionid) && options.oldunionid != "") {
		wx.setStorageSync('oldunionid', options.oldunionid);
	}

	var oldunionid = wx.getStorageSync('oldunionid');
	if ( !util.judge.isNull(oldunionid) && oldunionid != "" ) {
		app.getUserInfo()
		.then(res => {
		  return wxRequest.postRequest(config.transfer, {oldunionid:oldunionid});
		})
		.then(res => {
			if(res==1 || res==99){
				wx.removeStorageSync('oldunionid');
			}
			if(res==1){
				util.alert("用户信息迁移成功");
			}
		})
		.catch(res => {
			util.alert_catch(res.message);
		})
		.finally(function (res) {
			util.hideLoading();
		});
	}
	else{
		app.getUserInfo();
	}
	  
},
scanf: function () {
    wx.scanCode({
      success: (res) => {
        var machine_code = res.result;
        console.log(machine_code);
        wx.navigateTo({
          url: '../../pages/pay/index?machine_code=' + machine_code
        })
      },
      fail: (res) => {
        this.show = "结果:" + res.result + "二维码类型:" + res.scanType + "字符集:" + res.charSet + "路径:" + res.path;
        this.setData({
          show: this.show
        })
      }
    })
  },
  repeart: function () {
	wx.navigateTo({
		url: '../../pages/repeat/index'
	});
  }

})
